package cn.com.demo.tp01.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("test")
@RestController
public class MainController {
    @Autowired
    private AmqpTemplate amqpTemplate;
    @GetMapping("get/{msg}")
    public String get(@PathVariable("msg")String msg ){
        String res ="Success";
        String exchange = "demo.direct";
        String routerKey = "demo.log.info";
        String message = "direct:" + msg;
        this.amqpTemplate.convertAndSend(exchange, routerKey, message);

        return res;

    }
    @GetMapping("topic/{msg}")
    public String topic(@PathVariable("msg")String msg ){
        String res ="Success";
        String exchange = "demo.topic";
        String routerKey = "demoa.log.info";
        String message = "topicA:" + msg;
        this.amqpTemplate.convertAndSend(exchange, routerKey, message);

        return res;

    }
    @GetMapping("fanout/{msg}")
    public String fanout(@PathVariable("msg")String msg ){
        String res ="Success";
        String exchange = "demo.fanout";
        String routerKey = "demoa.log.info";
        String message = "fanout:" + msg;
        this.amqpTemplate.convertAndSend(exchange, routerKey, message);

        return res;
    
    }
}
